#!/usr/bin/python
# -*- coding:utf-8 -*-

import json
import datetime
import bson
import arrow


class DateTimeEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return arrow.Arrow.fromdatetime(obj).for_json()
        elif isinstance(obj, bson.ObjectId):
            return str(obj)
        else:
            return json.JSONEncoder.default(self, obj)
